package com.example.zy5_project_jetpack.mvp.view.SofaFragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zy5_project_jetpack.R;
import com.example.zy5_project_jetpack.mvp.view.FindFragment.LikeFragment;
import com.example.zy5_project_jetpack.mvp.view.FindFragment.ReCommentFragment;
import com.example.zy5_project_jetpack.mvp.view.FragmentAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class SofaFragment extends Fragment {
    private TabLayout tab_sofa;
    private ViewPager view_sofa_pager;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_sofa, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        tab_sofa = view.findViewById(R.id.tab_sofa);
        view_sofa_pager = view.findViewById(R.id.view_sofa_pager);
        final ArrayList<Fragment> fragments = new ArrayList<>();

        fragments.add(new ImageFragment());
        fragments.add(new VideoFragment());
        fragments.add(new TextFragment());

        FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager(), fragments);

        view_sofa_pager.setAdapter(fragmentAdapter);
        tab_sofa.setupWithViewPager(view_sofa_pager);
        tab_sofa.getTabAt(0).setText("图片");
        tab_sofa.getTabAt(1).setText("视频");
        tab_sofa.getTabAt(2).setText("文本");
    }
}